﻿' <summary>
' BeeWit IDE Entorno de desarrollo Visual para php.
' BeeWitPHP IDE es el único entorno de desarrollo para PHP 
' de tipo WYSIWYG (What You See Is What You Get). 
' ¡Ahora si!, aproveche la potencia del lenguaje PHP 
' y desarrolle más rápidamente gracias a la programación 
' intuitiva de BeeWit.
' Copyright © 2010 Dewins Murillo Garcia 
' EMAIL: dewinsmg@gmail.com
' EMAIL: dewins@beewitsoft.com
' Este Programa es Software Libre: usted puede redistribuirlo 
' y/o modificarlo bajo los términos de la Licencia Publica General 
' GNU como es publicada por la Fundacion de Software Libre; 
' en la 3ra versión de la licencia.
' Este programa es distribuido con la esperanza de que sea útil, 
' pero SIN GARANTÍA ALGUNA; sin siquiera la garantía implícita 
' de VALOR COMERCIAL o FORMADO PARA UN PROPÓSITO EN PARTICULAR. 
' Vea la Licencia Publica General GNU para mas detalles.
' Usted debe haber recibido una copia de la Licencia Publica General 
' GNU junto con este programa. Si no, vaya a http://www.beewitsoft.com
' o en http://code.google.com/p/ajax-beewit-php-ide/
' </summary>
' <remarks></remarks>

Imports mshtml

Public Class ctlHTMLTable
    Event OnAcept()
    Event OnCancel()

    Private Sub btnInsert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnInsert.Click
        Dim Editor As ctlEditor = General.Control_Main.ActualEditor
        If Not Editor Is Nothing Then
            Dim dato As String = "hello"
            Dim mytable As HtmlElement
            Dim mytbody As HtmlElement
            ' Editor.HTML.HTML.ExecCommand("inserthtml", False, dato)
            If Editor.HTML.SelectedElement.TagName = "TABLE" Then
                mytable = General.Control_Main.ActualEditor.HTML.SelectedElement
                mytable.SetAttribute("cellpadding", Me.txtCellPadding.Value.ToString())
                mytable.SetAttribute("cellspacing", Me.txtCellSpacing.Value.ToString())
                mytable.SetAttribute("align", Me.cmbTextAlignment.Text.ToString())
                mytable.SetAttribute("border", Me.txtBorderSize.Text.ToString())
                mytable.SetAttribute("width", Me.txtTableWidth.Text.ToString())
                mytable.SetAttribute("summary", Me.txtTableCaption.Text.ToString())

                mytable.Style &= "cellpadding:" & Me.txtCellPadding.Value.ToString() & ","
                mytable.Style &= "cellspacing:" & Me.txtCellSpacing.Value.ToString() & ","
                mytable.Style &= "align:" & Me.cmbTextAlignment.Text.ToString() & ","
                mytable.Style &= "border:" & Me.txtBorderSize.Value.ToString() & ","
                mytable.Style &= "width:" & Me.txtTableWidth.Value.ToString() & ","
            Else
                mytable = Editor.HTML.HTML.CreateElement("table")
                mytbody = Editor.HTML.HTML.CreateElement("tbody")
                mytable.SetAttribute("cellpadding", Me.txtCellPadding.Value.ToString())
                mytable.SetAttribute("cellspacing", Me.txtCellSpacing.Value.ToString())
                mytable.SetAttribute("align", Me.cmbTextAlignment.Text.ToString())
                mytable.SetAttribute("border", Me.txtBorderSize.Text.ToString())
                mytable.SetAttribute("width", Me.txtTableWidth.Text.ToString())
                mytable.SetAttribute("summary", Me.txtTableCaption.Text.ToString())

                For i As Long = 1 To Me.txtRows.Text
                    Dim mytr As HtmlElement = Editor.HTML.HTML.CreateElement("tr")
                    mytbody.AppendChild(mytr)
                    For j As Long = 1 To Me.txtColumns.Text
                        Dim mytd As HtmlElement = Editor.HTML.HTML.CreateElement("td")
                        mytr.AppendChild(mytd)
                    Next
                Next
                mytable.AppendChild(mytbody)
            End If
            'Editor.HTML.SelectedElement.AppendChild(mytable)
            Dim HtmlDataToPaste As String = HtmlDataCopied
            Dim htmlDocument As IHTMLDocument2 = General.Control_Main.ActualEditor.webDesign.Document.DomDocument
            Dim currentSelection As IHTMLSelectionObject = htmlDocument.selection
            If Not currentSelection Is Nothing Then
                Dim range As IHTMLTxtRange = currentSelection.createRange()
                If Not range Is Nothing Then
                End If
            End If
            Editor.HTML.SelectedElement.AppendChild(mytable)
        End If

        RaiseEvent OnAcept()
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        RaiseEvent OnCancel()
    End Sub

    Private Sub ctlHTMLTable_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If General.Control_Main.ActualEditor.HTML.SelectedElement.TagName = "TABLE" Then
            Me.txtBorderSize.Value = Val(General.Control_Main.ActualEditor.HTML.SelectedElement.GetAttribute("border"))
            Me.txtCellPadding.Value = Val(General.Control_Main.ActualEditor.HTML.SelectedElement.GetAttribute("cellpadding"))
            Me.txtCellSpacing.Value = Val(General.Control_Main.ActualEditor.HTML.SelectedElement.GetAttribute("cellspacing"))
            'Me.txtColumns.Value = Val(General.Control_Main.ActualEditor.HTML.SelectedElement.GetAttribute("border"))
            'Me.txtRows.Value = Val(General.Control_Main.ActualEditor.HTML.SelectedElement.GetAttribute("border"))
            Me.txtTableCaption.Text = Val(General.Control_Main.ActualEditor.HTML.SelectedElement.GetAttribute("sumary"))
            Me.txtTableWidth.Value = Val(General.Control_Main.ActualEditor.HTML.SelectedElement.GetAttribute("width"))
        End If
    End Sub
End Class
